﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C2
{
    public class TimeEventArgs : EventArgs
    {
        public int hour;
        public int minute;
        public int second;
    }
    public delegate void TickEventHandler(object sender, TimeEventArgs args);
    public delegate void AlarmEventHandler(object sender, TimeEventArgs args);
    class timeAlarm
    {
        public event TickEventHandler tick;
        public event AlarmEventHandler alarm;
        public void timeruning()
        {
            int second = DateTime.Now.Second;
            int old = 0;
            int minute = 0;
            while (true)
            {
                second = DateTime.Now.Second;
                minute = DateTime.Now.Minute;
                if (old != second)
                {
                    old = second;
                    TimeEventArgs args = new TimeEventArgs();
                    args.hour = DateTime.Now.Hour;
                    args.second = DateTime.Now.Second;
                    args.minute = DateTime.Now.Minute;
                    if (alarm != null&& second % 10 == 0 )
                    {
                        alarm(this, args);
                    }
                    if (tick != null)
                    {
                        tick(this, args);
                    }
                }
            }
            
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            timeAlarm timealarm = new timeAlarm();
            timealarm.alarm += showalarm;
            timealarm.tick += showTick;
            timealarm.timeruning();
        }
        static void showTick(object sender, TimeEventArgs args)
        {
            Console.WriteLine(args.hour + ":" + args.minute + ":" + args.second + ":" + "tick");
        }
        static void showalarm(object sender, TimeEventArgs args)
        {
            Console.WriteLine(args.hour + ":" + args.minute + ":" + args.second + ":" + "alarm");
        }
    }
}
